
var prefix = "/jzweb/examinationAnswerSheetCom";

$(function (){
	getExamList()
})

function getExamList(){
	$.ajax({
		type : 'post',
		url : '/jzweb/mark/selEbatchIdLiLuen',
		contentType: 'application/json',
		data: JSON.stringify( {competitionType:sessionStorage.getItem("competitionTypes") ? sessionStorage.getItem("competitionTypes") : 'null'} ),
		success : function(r) {
			if (r.code == 0) {
				//console.log("r"+JSON.stringify(r))
				var str = '';
				r.data.map(function (v,k){
					str += `<option name="${v.cbatchId}" value="${v.id}">${v.name}</option> `
				})
				$("#id").html(str);
				getCaiData();
			} else {
				layer.msg(r.msg);
			}
		}
	});
}

var cbatchId = ''
var ebatchId = ''
var stuId = ''
var strDataRight = '';
var strDataLeft = '';
var arrData = '' , startPage = 1 , loadcurrPages = 0;

function reload(){
	sessionStorage.removeItem('cacheIndex');
	getCaiData();
}

function getCaiData(){

	$('#examName').html($("#id").find("option:selected").text())
	$.ajax({
		url:'/jzweb/examinationAnswerSheetCom/examinationAnswerSheetCom',
		beforeSend:function (){
			layer.load()
		},
		data: {
			id1:sessionStorage.getItem("refereeId"),
			id2: $("#id").val() ,
			cbatchId: $("#id").find("option:selected").attr('name') ,
			current: startPage,
			number: 50
		},
		async: false,
		type:'POST',
		success:function (r) {
			layer.closeAll();
			if (r.code == 0){
				arrData = r.data.records
				if(arrData.length>0){
					$('#showExamType').show()
					$('#noDat').hide()

					strDataRight = '';
					arrData.forEach(function (item, index, arr) {
						strDataRight += `<li class="${index == 0?'selected':''}">
						<a href="#">${item.num2}</a>
						<input type="hidden" value="${item.cbatchId}" class="cbatchId">
						<input type="hidden" value="${item.ebatchId}" class="ebatchId">
						<input type="hidden" value="${item.stuId}" class="stuId">
						
					</li>`;
					})

					$('#listBox').html(strDataRight)

					layui.use(['laypage', 'layer'], function() {
						var laypage = layui.laypage
							, layer = layui.layer;
						laypage.render({
							elem: 'grid_paging_part'
							, theme: '#1E9FFF'
							,count: r.data.total
							,limit: 50
							,groups: 5
							// ,layout:['count','page','skip']
							,jump: function(obj,first){
								if(!first){
									startPage = obj.curr;
									getCaiData();
								}
							}
							, curr: startPage
						});
					})

					$(".listBox").find('li').eq(sessionStorage.getItem('cacheIndex')).addClass('selected');

					$(".listBox").find('li').click(function (){
						sessionStorage.setItem('cacheIndex',$(this).index())
						$(this).attr('data-index',$(this).index()) ;

						$(".selected").removeClass('selected');
						$(this).addClass('selected');

						cbatchId =   $(this).find('.cbatchId').val()
						ebatchId =   $(this).find('.ebatchId').val()
						stuId = $(this).find('.stuId').val()

						var index = $(this).index();

						let numIndex = index+1
						strDataLeft = ''

						arrData.slice(index,numIndex).forEach(function (item, index2, arr) {

							if(item.markDOS!=null){
								item.markDOS.forEach(function (item1, index1, arr1) {
									strDataLeft += `
							<div class="userList">
<!--								<p class="titleA">${item.court}-赛场</p>-->
								
								<p class="caption">${item1.content}</p>
								<div class="answer">
<!--									<div class="form-control rubr textareaAnswer">${item1.answerList}</div>-->
									<input type="text" value="" class="inputType form-control mark ${item1.updateScore != null?'showMyInput':''}" id="grade${index1}" placeholder="请输入您的分数,0-100之间"  oninput="if(value>100||value<0){value = 100}">
									<div id="myGrade${index1}" style="margin-top: 10px" class="dafenNum ${item1.updateScore != null?'showMyScore':''}"" >您的打分：<span class="score">${item1.updateScore}</span> <span style="cursor: pointer" onclick="dafen('grade${index1}','myGrade${index1}','subGrade${index1}','editGrade${index1}')" class="dayFont"><img src="../../../img/updata.png" class="loginData" data-leve="oneLevelUpdateCom" data-reve="reveal1" data-drag="grade" width="20">修改分数</span></div>
								</div>
								
								<div class="remark" style="margin-bottom: 20px;width: 70%;">
									<p>备注：</p>
									<textarea class="form-control" placeholder="请输入你的备注" id="refereeRemark" value="${item1.refereeRemark || ''}">${item1.refereeRemark || ''}</textarea>
								</div>
								
								<div class="form-group ${item1.score != null?'showMyInput':''}" id="subGrade${index1}">
									<div class="col-sm-4 col-sm-offset-4">
										<button type="button" onclick="update('/jzweb/mark/judgeMark','grade${index1}','fractionA')" class="btn btn-primary btn-block" id="oneLevelUpdateCom">提交</button>
									</div>
								</div>
								
								<div class="form-group clickDfen" id="editGrade${index1}">
									<div class="col-sm-4 col-sm-offset-4">
										<button type="button" onclick="update1('/jzweb/mark/conservatorJudgeMark','grade${index1}','${item1.id}')" class="btn btn-primary btn-block" id="fractionClick">提 交</button>
									</div>
								</div>
							</div>
						`;
								})
							}
						})

						$('#allQuestion').html(strDataLeft)

					})
					$(".listBox").find('.selected').click();

				}else{
					$('#listBox').html('')
					$('#showExamType').hide()
					$('#noDat').show()
				}

			}else{
				$('#listBox').html('')
				$('#showExamType').hide()
				$('#noDat').show()
			}
		}
	})
}
$(".loginData").click(function (){
	$(".shade").show();
	$(".fixedner").show();
	$(".fixedner").attr({'data-drag':$(this).attr('data-drag'),'data-leve':$(this).attr('data-leve'),'data-reve':$(this).attr('data-reve')})
})

$("#close").click(function (){
	$(".shade").hide();
	$(".fixedner").hide();
})
$(".shadeHide").click(function (){
	$(".shade").hide();
	$(".fixedner").hide();
})
var idType = ''
var myIdType = ''
var subType = ''
var editType = ''
$("#loginInfo").click(function (){
	let obj = {
		userName: $("#username").val() ,
		passWord: $("#password").val()
	}
	$.ajax({
		cache : true,
		type : "post",
		url : '/jzweb/examinationAnswerSheetCom/oneLevelLogin',
		data : obj,// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				$(".shade").hide();
				$(".fixedner").hide();

				$("#"+idType).show()
				$("#"+myIdType).hide()
				$("#"+subType).hide()
				$("#"+editType).show()

				$("#"+$(".fixedner").attr('data-drag')).show();
				$("#"+$(".fixedner").attr('data-leve')).show();
				$("."+$(".fixedner").attr('data-reve')).hide();
				parent.layer.msg("登录成功");
			} else {
				parent.layer.alert(data.msg)
			}

		}
	});
})

function dafen(id,myId,subId,editId){
	console.log('dafen',id)
	idType = id
	myIdType = myId
	subType = subId
	editType = editId
	$(".shade").show();
	$(".fixedner").show();
}

function update(url,ev,parame) {

	if( !$("#"+ev).val() ){
		layer.msg('请填写打分项!!!');
		return false;
	}

	let makk = $("#"+ev).val() == '' ? 0 : $("#"+ev).val()

	if( makk > 18 ){
		layer.msg('请勿超过18分');
		return false;
	}

	layer.open({
		content: '你的打分为'+ makk
		,btn: ['确定', '取消']
		,yes: function(index, layero){
			var index = layer.load();

			let obj = {
				refereeId:	sessionStorage.getItem("refereeId"),
				//examBatchId: $(".selected").find(".examBatchId").val(),
				updateScore : $("#"+ev).val(),
				competition:'A',
				jinzhuanTopicId: sessionStorage.getItem("refereesNumber"),
				cbatchId:cbatchId,// 认证批次
				ebatchId:ebatchId,  //考试批次
				signId:stuId,//考生id
				picture:'null',
				video:'null',
				raceId:4,
				refereeRemark:$("#refereeRemark").val()
			}

			$.ajax({
				cache : true,
				type : "POST",
				url : url,
				contentType: 'application/json',
				data : JSON.stringify(obj),// 你的formid
				async : false,
				error : function(request) {
					parent.layer.alert("Connection error");
				},
				success : function(data) {
					if (data.code == 0) {
						layer.closeAll()
						//console.log($(".active").context.URL.replace(/#/g,''))
						//window.location.href = $(".active").context.URL.replace(/#/g,'');
						getCaiData();
						$("#"+ev).val('');
						parent.layer.msg("操作成功");
						sessionStorage.setItem('cacheIndex',$(".listBox").find('.selected').attr('data-index'))
					} else {
						parent.layer.alert(data.msg)
						layer.closeAll()
					}

				}
			});

		}
		,btn2: function(index, layero){
			//按钮【按钮二】的回调

			//return false 开启该代码可禁止点击该按钮关闭
		}
	});



	// let obj = {
	// 	id:	$(".selected").find('.id').val(),
	// 	examBatchId: $(".selected").find(".examBatchId").val(),
	// 	[parame] : $("#"+ev).val()
	// }


}

function update1(url,ev,id) {
	if( !$("#"+ev).val() ){
		layer.msg('请填写打分项!!!');
		return false;
	}

	let makk = $("#"+ev).val() == '' ? 0 : $("#"+ev).val()

	if( makk > 18 ){
		layer.msg('请勿超过18分');
		return false;
	}

	layer.open({
		content: '你的打分为'+ makk
		,btn: ['确定', '取消']
		,yes: function(idx, layero){
			//按钮【按钮一】的回调
			let obj = {
				updateScore : $("#"+ev).val(),
				id:id,
				picture:'null',
				video:'null',
				refereeRemark:$("#refereeRemark").val()
			}

			$.ajax({
				cache : true,
				type : "POST",
				url : url,
				data : JSON.stringify(obj),// 你的formid
				contentType: 'application/json',
				async : false,
				error : function(request) {
					parent.layer.alert("Connection error");
				},
				success : function(data) {
					if (data.code == 0) {
						layer.closeAll()
						$("#"+ev).val('');
						getCaiData();
						parent.layer.msg("操作成功");
						sessionStorage.setItem('cacheIndex',$(".listBox").find('.selected').attr('data-index'))
					} else {
						parent.layer.alert(data.msg)
						layer.closeAll()
					}

				}
			});
		}
		,btn2: function(index, layero){
			//按钮【按钮二】的回调

			//return false 开启该代码可禁止点击该按钮关闭
		}
	});

	// let obj = {
	// 	id:	$(".selected").find('.id').val(),
	// 	examBatchId: $(".selected").find(".examBatchId").val(),
	// 	[parame] : $("#"+ev).val()
	// }


}
//刷新iframe
function refreshTab() {
	var $pageTabsContent = $('.page-tabs-content');
	$pageTabsContent.children("[data-id]").each(function () {
		if($(this).hasClass('active')==true){
			var target = $('.J_iframe[data-id="' + $(this).data('id') + '"]');
			// console.log("target",target);
			var url = target.attr('src');
			//显示loading提示
			var loading = layer.load();
			target.attr('src', url).load(function () {
				//关闭loading提示
				layer.close(loading);
			});
		}
	});
	// $pageTabsContent.css("margin-left", "0");

}